const dbutil = require('../../../libs/MyDB');

module.exports = {
    getTabletypeInfo: async function () {
        let tabletypes = [];
        await dbutil.multiSelect('res_tabletype', ['tabletype_id', 'tabletype_number', 'tabletype_people','tabletype_time'])
            .then(
                result => {
                    tabletypes = result;
                }
            )
        for(let i =0;i<tabletypes.length;i++){
        let date = new Date(tabletypes[i].tabletype_time);
        let y = date.getFullYear();
        let m = date.getMonth()+1;
        let d = date.getDate();
        let time = `${y}-${m<10?'0'+m:m}-${d<10?'0'+d:d}`;
        tabletypes[i].tabletype_time = time;
        }
        return {
            code: 0,
            msg: "查询成功",
            data: tabletypes,
            count: tabletypes.length,
        }
    },
    addTabletype: async function(data){
        await dbutil.add('res_tabletype',data);
        return {
            code:200,
            msg: '添加成功',
        }
    },
    editTabletype: async function(data){

        await dbutil.update('res_tabletype',`tabletype_id=${data.tabletype_id}`,data);

        return {
            code:200,
            msg: '修改成功',
        }
    },
    delTabletype: async function(data){
        await dbutil.del('res_tabletype',`tabletype_id=${data.tabletype_id}`);

        return {
            code:200,
            msg: '删除成功',
        }
    }
}